package com.lizba.redis.limit.tokenbucket;

import io.lettuce.core.RedisClient;

/**
 * <p>
 *      测试令牌桶限流
 *      测试参数 cl.throttle liziba 10 5 60 1
 * </p>
 *
 * @Author: Liziba
 * @Date: 2021/9/9 0:02
 */
public class TestTokenBucketRateLimiter {

    public static void main(String[] args) {
        RedisClient client = RedisClient.create("redis://192.168.211.108:6379");
        TokenBucketRateLimiter limiter = new TokenBucketRateLimiter(client);
        // cl.throttle liziba 10 5 60 1
        for (int i = 1; i <= 15; i++) {
            boolean success = limiter.isActionAllowed("liziba", 10, 5, 60, 1);
            System.out.println("第" + i + "次请求" + (success ? "成功" : "失败"));
        }

    }

}
